//https://www.nowcoder.com/practice/389fc1c3d3be4479a154f63f495abff8?tpId=13&tqId=1375231&ru=%2Fpractice%2F2a49359695a544b8939c77358d29b7e6&qru=%2Fta%2Fcoding-interviews%2Fquestion-ranking&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D13
// 重点！！！ 异或-》分流的思想；

#include <limits>
#include <vector>
#include <math.h>

using namespace std;

class Solution {
  public:
    vector<int> FindNumsAppearOnce(vector<int>& array) {
        vector<int> res(2, 0);
        int temp = 0;
        //遍历数组得到a^b
        for (int i = 0; i < array.size(); i++)
            temp ^= array[i];
        unsigned int k = temp - (temp & (temp - 1));
        //找到两个数不相同的第一位
        // while ((k & temp) == 0)
        //     k <<= 1;
        for (int i = 0; i < array.size(); i++) {
            //遍历数组，对每个数分类
            if ((k & array[i]) == 0)
                res[0] ^= array[i];
            else
                res[1] ^= array[i];
        }
        //整理次序
        if (res[0] < res[1])
            return res;
        else
            return {res[1], res[0]};
    }
};